package com.yocard.yxyd.base;

import android.app.Application;
import android.content.Context;

import com.mob.MobSDK;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.commonsdk.statistics.common.DeviceConfig;
import com.yocard.yxyd.di.component.AppComponent;
import com.yocard.yxyd.di.component.DaggerAppComponent;
import com.yocard.yxyd.di.module.AppModule;
import com.yocard.yxyd.utils.util.LogUtils;
import com.yocard.yxyd.utils.util.Utils;

import cn.jpush.android.api.JPushInterface;

public class AppContext extends Application {
    public static AppComponent appComponent;
    private static AppContext instance;

    @Override
    public void onCreate() {
        super.onCreate();
//        if (LeakCanary.isInAnalyzerProcess(this)) {
//            // This process is dedicated to LeakCanary for heap analysis.
//            // You should not init your app in this process.
//            return;
//        }
//        LeakCanary.install(this);

        instance = this;
        Utils.init(this);
        MobSDK.init(this);
        UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, "");
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
        LogUtils.getConfig().setLogSwitch(true);
        //打印测试设备码
//        getTestDeviceInfo(this);
    }

    public static String[] getTestDeviceInfo(Context context){
        String[] deviceInfo = new String[2];
        try {
            if(context != null){
                deviceInfo[0] = DeviceConfig.getDeviceIdForGeneral(context);
                deviceInfo[1] = DeviceConfig.getMac(context);
            }
        } catch (Exception e){
        }
        LogUtils.d("{\"device_id\": \""+ deviceInfo[0] +"\", \"mac\": \""+ deviceInfo[1] + "\"}");
        return deviceInfo;
    }

    public static Context getContext() {
        return instance;
    }

    public static AppComponent getAppComponent() {
        if (appComponent == null) {
            appComponent = DaggerAppComponent.builder()
                    .appModule(new AppModule(instance))
                    .build();
        }
        return appComponent;
    }

    public static int getColor_(int resId) {
        return getContext().getResources().getColor(resId);
    }
}
